﻿package fpc.controls;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import fpc.ALayoutable;
import fpc.utils.Maths;

class DisplayObjectWrapper extends ALayoutable
{
	var _scaled:Bool;
	
	public function new(object:DisplayObject, scaled:Bool = false)
	{
		super();
		_scaled = scaled;
	}
	
	public override function addTo(parent:DisplayObjectContainer, index = Maths.INT_NULL)
	{
		if (index == Maths.INT_NULL)
		{
			parent.addChild(_object);
		}
		else
		{
			parent.addChildAt(_object, index);
		}
	}
	
	var _object:DisplayObject;
	
	override function setX(value)
	{
		_object.x = Math.round(value);
		return _x = value;
	}
	
	override function setY(value)
	{
		_object.y = Math.round(value);
		return _y = value;
	}
	
	override function getWidth()
	{
		return _object.width;
	}
	override function setWidth(value)
	{
		if (_scaled)
		{
			_object.width = Math.round(value);
		}
		return _object.width;
	}
	
	override function getHeight()
	{
		return _object.height;
	}
	override function setHeight(value)
	{
		if (_scaled)
		{
			_object.height = Math.round(value);
		}
		return _object.height;
	}
}